import javax.naming.Name;
import java.util.Scanner;

/**
 * Date: 2023-05-02
 * Time: 17:36
 */
public class practice {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        while (true) {
            try {
                System.out.println("请输入心仪对象的姓名");
                String name = sc.nextLine();
                if(name.length()<3 || name.length()>10){
                    throw new NameFormatException();
                }

                System.out.println("请输入心仪对象的年龄");
                int age = sc.nextInt();
                if(age<18 || age>40){
                    throw new AgeOutOfBoundsException();
                }
                break;
            } catch(NumberFormatException | NameFormatException | AgeOutOfBoundsException e){
                e.printStackTrace();
            }
        }
    }
}
